package com.addedstuff;

import brianchen.util;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.effect.EntityLightningBolt;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumToolMaterial;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemSword;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;

public class thorhammer extends Item{
//this jumps high,causes lightning damage and knockback effect. it does 1,000,000 damage
	public thorhammer(int par1, EnumToolMaterial par2EnumToolMaterial) 
	{
		super (par1);
		this.setCreativeTab(CreativeTabs.tabCombat);
		// TODO Auto-generated constructor stub
		
	}
	 public void registerIcons(IconRegister iconReg)
	    {
	        itemIcon = iconReg.registerIcon("Brianmodbase:thorhammer.fw");
	    }
	 public int getDamageVsEntity (Entity par1Entity)
	 {
		 return 1000000;
	 }
	 
		public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) 
		{
			if (!par2World.isRemote)
			{
			
			     
		        par3EntityPlayer.addPotionEffect(new PotionEffect(Potion.jump.id, 100, 50));
		        par3EntityPlayer.addPotionEffect(new PotionEffect(Potion.moveSpeed.id, 1000, 120));
		        par3EntityPlayer.addPotionEffect(new PotionEffect(Potion.resistance.id, 19999, 9999));
		        par1ItemStack.damageItem(3, par3EntityPlayer);
			
                MovingObjectPosition Coord = par3EntityPlayer.rayTrace(300, 1);
                if (Coord != null) 
                {
                        EntityLightningBolt Lightning = new EntityLightningBolt(par2World, Coord.blockX, Coord.blockY, Coord.blockZ);

                        for (int i = 3; i > -2; i--) 
                        {
                            par2World.spawnEntityInWorld(new EntityLightningBolt(par2World, Coord.blockX + i * 2, Coord.blockY,Coord.blockZ));
                            par2World.addWeatherEffect(Lightning);
                        }
                }
        

   
				for (Object _entity : par2World.loadedEntityList)
				{
					try 
					{
						EntityLiving living = (EntityLiving)_entity;
						if (living != null)
						{
							if (living.getEntityName() != par3EntityPlayer.getEntityName())
							{
								if (living.getPosition(1).distanceTo(par3EntityPlayer.getPosition(1))< 10)
								{
									Vec3 dir = par3EntityPlayer.getPosition(1).subtract(living.getPosition(1));
									dir = dir.normalize();
									float speed = 100;
									living.setVelocity(dir.xCoord*speed, dir.yCoord, dir.zCoord*speed);
								}
							
							}
						}
					}
					catch(Exception e)
					{
						
					}
			
				}
			}
			return par1ItemStack;
		}
		public boolean hasEffect(ItemStack par1ItemStack) {
            return true;
    }
}
